package com.interceptor;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import java.util.Map;

public class MyInterceptor extends AbstractInterceptor 
{
	
	public void init()
	{
		System.out.println("you are init method");
	}
	
	public void destroy()
	{
		System.out.println("method destroyed");
	}

	@Override
	public String intercept(ActionInvocation invocation) throws Exception 
	{
			ActionSupport actionSupport = (ActionSupport)invocation.getAction();
			Map session = invocation.getInvocationContext().getSession();
			if(session.get("user")==null)
			{
				actionSupport.addActionError("Opp! your session hasbeen expired");
				return "logout";
			}
		return invocation.invoke();
	}
	
}
